package com.xzx.study.animation;

import android.graphics.drawable.AnimationDrawable;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import com.xzx.study.R;

public class DrawableAnimationActivity extends AppCompatActivity implements View.OnClickListener {

    private Button drawable_anim_start;
    private Button drawable_anim_stop;

    private ImageView drawable_anim_iv;
    private AnimationDrawable animationDrawable;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_drawable_animation);

        drawable_anim_start = findViewById(R.id.drawable_anim_start);
        drawable_anim_stop = findViewById(R.id.drawable_anim_stop);
        drawable_anim_iv = findViewById(R.id.drawable_anim_iv);


        drawable_anim_stop.setOnClickListener(this);
        drawable_anim_start.setOnClickListener(this);

        animationDrawable = (AnimationDrawable) drawable_anim_iv.getBackground();
    }

    @Override
    public void onClick(View v) {
        if (drawable_anim_start == v) {
            animationDrawable.start();
        } else if (drawable_anim_stop == v) {
            animationDrawable.stop();
        }
    }
}
